<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@include file="../contextjs.jsp" %>
</head>
<body>
	<div id="cc" class="easyui-layout" style ="width:800px;height:600px;margin: auto;">   
	    <div data-options="region:'north',split:true,collapsible:false" style="height:100px;">
	    	<div style="text-align: center;padding-top: 5%">
	    		<input id="search" class="easyui-textbox" data-options="iconCls:'icon-search'" style="width:50%;height: 35px;font: 28px;" > 
	    		<input type="button" value="搜索"  id="btn" /> 
	    	</div>
	    </div>   
	    <div data-options="region:'south',split:true,collapsible:false" style="height:100px;">
	    	
	    </div>   
	    <div data-options="region:'center',collapsible:false" style="background:#eee;height: 80%;">
		    <table  id="dd" class="easyui-datagrid">   
			</table>  
	    </div>   
	</div>
	<div id="gg"></div>  
</body>
 <script type="text/javascript">
        $(function () {    	
            var datagrid; //定义全局变量datagrid
            var editRow = undefined; //定义全局变量：当前编辑的行
            datagrid = $("#dd").datagrid({
                url: 'user_CusList.action', //请求的数据源
                iconCls: 'icon-save', //图标
                pagination: true, //显示分页
                pageSize: 15, //页大小
                pageList: [15, 30, 45, 60], //页大小下拉选项此项各value是pageSize的倍数
                fit: true, //datagrid自适应宽度
                fitColumns: true, //列自适应宽度
                striped: true, //行背景交换
                nowap: true, //列内容多时自动折至第二行
                border: false,
                idField: 'userid', //主键
                queryParams: { search: $("#search").val()}, //查询参数
                columns: [[//显示的列
                {field: 'userid', title: '编号', width: 100, sortable: true, checkbox: true },
                 { field: 'uname', title: '用户名', width: 100, sortable: true,
                     editor: { type: 'validatebox', options: { required: true} }
                 },
                  { field: 'upsw', title: '密码', width: 100,
                      editor: { type: 'validatebox', options: { required: true} }
                  }
                   ]],
                toolbar: [
                 { text: '添加', iconCls: 'icon-add', handler: function () { 
                		var url="user_addormodify.action?status=add";
                	 	$('#gg').dialog('refresh', url);  
                	 	gg.dialog('open');
                	   }
                 },"-",
                { text: '修改', iconCls: 'icon-add', handler: function () { 
                	 	var row= $('#dd').datagrid('getSelected');
                	 	var url="user_addormodify.action?status=modify&userid="+row.userid;
                	 	$('#gg').dialog('refresh', url);  
             	 		gg.dialog('open');
             	   }
                 }
                 //,"-",
                // { text: '赋予角色', iconCls: 'icon-add', handler: function () { 
             	 	//var row= $('#dd').datagrid('getSelected');
             	 	///var url="role_RoletoUserSelect.action?userid="+row.userid;
            	 	//$('#gg').dialog('refresh', url);  
             	 	//$('#gg').dialog('open');
          	       //}
                 //}
                 ,"-",
                 { text: '删除', iconCls: 'icon-remove', handler: function () {
                     //删除时先获取选择行
                     var rows = datagrid.datagrid("getSelections");
                     //选择要删除的行
                     if (rows.length > 0) {
                         $.messager.confirm("提示", "你确定要删除吗?",function (r) {
                             if (r) {
                                 var ids = [];
                                 for (var i = 0; i < rows.length; i++) {
                                     ids.push(rows[i].userid);
                                 }
                                 //将选择到的行存入数组并用,分隔转换成字符串，
                                 //本例只是前台操作没有与数据库进行交互所以此处只是弹出要传入后台的id
                                 //alert(ids.join(','));
                                 $.ajax({
                                     type : "POST",
                                     url : "user_delete.action",
                                     dataType : "text",
                                     traditional : true,
                                     data : {
                                             //此处跟后台对应
                                             ids : ids
                                             },
                                     success : function(data) {
                                    	 alert(data);
                                    	 //删除刷新
                                    	 $("#dd").datagrid("load");
                                    	 //取消编辑
                                    	 datagrid.datagrid("unselectAll");
                                     },error :function(data){
                                    	 alert("error");
                                     }
                                     
                                     });
                                 //刷新
                                 
                             }
                         });
                     }
                     else {
                         $.messager.alert("提示", "请选择要删除的行", "error");
                     }
            	 }
             }],
                 
                onAfterEdit: function(rowIndex, rowData, changes) {
                		}
                	});
            
           var gg=$('#gg').dialog({
                title: '用户',
                width: 500,
                height: 400,
                closed: true,
                cache: false,
                href: "user_addormodify.action",
                modal: true
            });
           
           $("#btn").click(function(){
       			$("#dd").datagrid("load",{search:$("#search").val()});
	       		//重载本页面
	       		//window.location.reload(); 
	       		//param=$("#search").val();
	       		//$('#dd').datagrid('reload');  
       	});
        });
    </script>
</html>